home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / man / url.sty (.txt) < prev    next >
Encoding:
LaTeX Document  |  1997-01-20  |  12.4 KB  |  219 lines

  1. % url.sty  ver 1.1    6-Feb-1996   Donald Arseneau   asnd@triumf.ca
  2. % A form of \verb that allows linebreaks at certain characters or 
  3. % combinations of characters, accepts reconfiguration, and can usually
  4. % be used in the argument to another command.  It is intended for email
  5. % addresses, hypertext links, directories/paths, etc., which normally 
  6. % have no spaces.  The font may be selected using the \urlstyle command, 
  7. % and new url-like commands can be defined using \urldef.
  8. % Usage:    Conditions:
  9. % \url{ }   If the argument contains any "%", "#", or "^^", or ends with
  10. %           "\", it can't be used in the argument to another command.  
  11. %           The argument must not contain unbalanced braces.
  12. % \url|  |  ...where "|" is any character not used in the argument and not 
  13. %           "{".  The same restrictions as above except that the argument
  14. %           may contain unbalanced braces.
  15. % \xyz      for "\xyz" a defined-url;  this can be used anywhere, no matter
  16. %           what characters it contains.
  17. % See further instructions after "\endinput"
  18. \def\url@ttstyle{%
  19. \@ifundefined{selectfont}{\def\UrlFont{\tt}}{\def\UrlFont{\ttfamily}}% 
  20. \def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\%\do\;\do\>\do\]%
  21.  \do\)\do\,\do\?\do\'\do\+\do\=\do@url@hyp}%
  22. \def\UrlBigBreaks{\do\:}%
  23. \def\UrlNoBreaks{\do\(\do\[\do\{\do\<}% (unnecessary)
  24. \def\UrlSpecials{\do\ {\ }}%
  25. \def\UrlOrds{\do\*\do\-}% any ordinary characters that aren't usually
  26. \def\url@rmstyle{%
  27. \@ifundefined{selectfont}{\def\UrlFont{\rm}}{\def\UrlFont{\rmfamily}}% 
  28. \def\UrlBreaks{\do\.\do\@\do\/\do\!\do\%\do\;\do\]\do\)\do\,\do\?\do@url@hyp
  29.   \do\+\do\=}%
  30. \def\UrlBigBreaks{\do\:}%
  31. \def\UrlNoBreaks{\do\(\do\[\do\{}% prevents breaks after *next* character
  32. \def\UrlSpecials{\do\<{\langle}\do\>{\rangle\penalty\relpenalty}\do\_{\_%
  33.  \penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\rbrace\penalty\relpenalty}\do
  34.  \\{\mathbin{\backslash}}\do\~{\mathord{{}^{\textstyle\sim}}}\do\ {\ }}%
  35. \def\UrlOrds{\do\'\do\"\do\-}%
  36. \def\url@sfstyle{\url@rmstyle 
  37. \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\sffamily}}% 
  38. \def\url@samestyle{\ifdim\fontdimen\thr@@\font=\z@ \url@ttstyle \else
  39.   \url@rmstyle \fi \def\UrlFont{}}
  40. \def\do@url@hyp{}% by default, no breaks after hyphens
  41. \@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{}
  42. \@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{}
  43. \def\Url{\relax\ifmmode\@nomatherr$\fi 
  44.  \UrlFont $\fam\z@ \textfont\z@\font 
  45.  \let\do\@makeother \dospecials % verbatim catcodes
  46.  \catcode`{\@ne \catcode`}\tw@ % except braces 
  47.  \medmuskip0mu \thickmuskip\medmuskip \thinmuskip\medmuskip
  48.  \@tempcnta\fam\multiply\@tempcnta\@cclvi 
  49.  \let\do\set@mathcode \UrlOrds % ordinary characters that were special
  50.  \advance\@tempcnta 8192 \UrlBreaks % bin
  51.  \advance\@tempcnta 4096 \UrlBigBreaks % rel
  52.  \advance\@tempcnta 4096 \UrlNoBreaks % open
  53.  \let\do\set@mathact \UrlSpecials % active
  54.  \let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures 
  55.  \@ifnextchar\bgroup\Url@z\Url@y}
  56. \def\Url@y#1{\catcode`{11 \catcode`}11
  57.   \def\@tempa##1#1{\Url@z{##1}}\@tempa}
  58. \def\Url@z#1{\def\@tempa{#1}\expandafter\expandafter\expandafter\Url@use
  59.   \expandafter\strip@prefix\meaning\@tempa\, \relax\m@th$\endgroup}
  60. \let\Url@use\@empty
  61. \def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta\mathcode`#1\count@}
  62. \def\set@mathact#1#2{\mathcode`#132768 \lccode`\~`#1\lowercase{\def~{#2}}}
  63. \def\set@mathnolig#1{\ifnum\mathcode`#1<32768
  64.    \lccode`\~`#1\lowercase{\edef~{\mathchar\number\mathcode`#1_{\/}}}%
  65.    \mathcode`#132768 \fi}
  66. \def\urldef#1#2{\begingroup \setbox\z@\hbox\bgroup
  67.   \def\Url@z{\Url@def{#1}{#2}}#2}
  68. \expandafter\ifx\csname DeclareRobustCommand\endcsname\relax
  69.   \def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup
  70.     \def#1{#2{#3}}}
  71. \else
  72.   \def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup
  73.     \DeclareRobustCommand{#1}{#2{#3}}}
  74. \def\urlstyle#1{\csname url@#1style\endcsname}
  75. % Sample (and default) configuration:
  76. \newcommand\url{\begingroup \Url}
  77. \newcommand\path{\begingroup \urlstyle{tt}\Url}
  78. % too many styles define \email like \address, so I will not define it.
  79. % \newcommand\email{\begingroup \urlstyle{rm}\Url}
  80. % Process LaTeX \package options
  81. \urlstyle{tt}
  82. \@ifundefined{ProvidesPackage}{}{
  83.   \ProvidesPackage{url}[1996/02/06 \space ver 1.1 \space 
  84.        Verb mode for urls, email addresses, and file names]
  85.   \DeclareOption{hyphens}{\def\do@url@hyp{\do\-}}% allow breaks after hyphens
  86.   \DeclareOption{obeyspaces}{\let\Url@use\relax}
  87.   \ProcessOptions
  88. \ifx\Url@use\relax \def\Url@use#1 #2{#1\ifx\relax#2\@empty\else
  89.   \penalty\relpenalty\ #2\expandafter\Url@use\fi}\fi
  90. \endinput
  91. % url.sty  ver 1.1    6-Feb-1996   Donald Arseneau   asnd@reg.triumf.ca
  92. % This package defines "\url", a form of "\verb" that allows linebreaks,
  93. % and can often be used in the argument to another command.  It can be
  94. % configured to print in different formats, and is particularly useful for 
  95. % hypertext links, email addresses, directories/paths, etc.  The font may 
  96. % be selected using the "\urlstyle" command and pre-defined text can be 
  97. % stored with the "\urldef" command. New url-like commands can be defined, 
  98. % and a "\path" command is provided this way. 
  99. % Usage:    Conditions:
  100. % \url{ }   If the argument contains any "%", "#", or "^^", or ends with 
  101. %           "\", it can't be used in the argument to another command.  
  102. %           The argument must not contain unbalanced braces.
  103. % \url|  |  ...where "|" is any character not used in the argument and not 
  104. %           "{".  The same restrictions as above except that the argument
  105. %           may contain unbalanced braces.
  106. % \xyz      for "\xyz" a defined-url;  this can be used anywhere, no matter
  107. %           what characters it contains.
  108. % The "\url" command is fragile, and its argument is likely to be very
  109. % fragile, but a defined-url is robust.
  110. % Package Option:  obeyspaces
  111. % Ordinarily, all spaces are ignored in the url-text.  The "[obeyspaces]" 
  112. % option allows spaces, but may introduce spurious spaces when a url
  113. % containing "\" characters is given in the argument to another command.  
  114. % So if you need to obey spaces you can say "\usepackage[obeyspaces]{url}",
  115. % and if you need both spaces and backslashes, use a `defined-url' for 
  116. % anything with "\".
  117. % Package Option:  hyphens
  118. % Ordinarily, breaks are not allowed after "-" characters because this 
  119. % leads to confusion. (Is the "-" part of the address or just a hyphen?)  
  120. % The package option "[hyphens]" allows breaks after explicit hyphen 
  121. % characters.  The "\url" command will *never ever* hyphenate words.
  122. % Defining a defined-url:
  123. % Take for example the email address "myself%node@gateway.net" which could
  124. % not be given (using "\url" or "\verb") in a caption or parbox due to the
  125. % percent sign.  This address can be predefined with 
  126. %    \urldef{\myself}\url{myself%node@gateway.net}   or
  127. %    \urldef{\myself}\url|myself%node@gateway.net|
  128. % and then you may use "\myself" instead of "\url{myself%node@gateway.net}"
  129. % in an argument, and even in a moving argument like a caption because a
  130. % defined-url is robust.
  131. % Style: 
  132. % You can switch the style of printing using "\urlstyle{tt}", where "tt"
  133. % can be any defined style.  The pre-defined styles are "tt", "rm", "sf", 
  134. % and "same" which all allow the same linebreaks but different fonts -- 
  135. % the first three select a specific font and the "same" style uses the
  136. % current text font.  You can define your own styles with different fonts 
  137. % and/or line-breaking by following the explanations below.  The "\url" 
  138. % command follows whatever the currently-set style dictates.
  139. % Alternate commands:
  140. % It may be desireable to have different things treated differently, each
  141. % in a predefined style; e.g., if you want directory paths to always be 
  142. % in tt and email addresses to be rm, then you would define new url-like
  143. % commands as follows:
  144. %    \newcommand\email{\begingroup \urlstyle{rm}\Url}
  145. %    \newcommand\directory{\begingroup \urlstyle{tt}\Url}
  146. % You must follow this format closely, and NOTE that the final command is 
  147. % "\Url", not "\url".  In fact, the "\directory" example is exactly the 
  148. % "\path" definition which is pre-defined in the package.  If you look 
  149. % above, you will see that "\url" is defined with
  150. %    \newcommand\url{\begingroup \Url}
  151. % I.e., using whatever url-style has been selected.
  152. % You can make a defined-url for these other styles, using the usual 
  153. % "\urldef" command as in this example:
  154. %    \urldef{\myself}{\email}{myself%node.domain@gateway.net}
  155. % which makes "\myself" act like "\email{myself%node.domain@gateway.net}",
  156. % if the "\email" command is defined as above.  The "\myself" command is
  157. % robust.
  158. % Defining styles:
  159. % Before describing how to customize the printing style, it is best to 
  160. % mention something about the unusual implementation of "\url".  Although
  161. % the material is textual in nature, and the font specification required
  162. % is a text-font command, the text is actually typeset in *math* mode.
  163. % This allows the context-sensitive linebreaking, but also accounts for
  164. % the default behavior of ignoring spaces.  Now on to defining styles.
  165. % To change the font or the list of characters that allow linebreaks, you
  166. % could redefine the commands "\UrlFont", "\UrlBreaks", "\UrlSpecials" etc.
  167. % directly in the document, but it is better to define a new `url-style' 
  168. % (following the example of "\url@ttstyle" and "\url@rmstyle") which defines 
  169. % all of "\UrlBigbreaks", "\UrlNoBreaks", "\UrlBreaks", "\UrlSpecials", and 
  170. % "\UrlFont".
  171. % Changing font:
  172. % The "\UrlFont" command selects the font.  The definition of "\UrlFont"
  173. % done by the pre-defined styles varies to cope with a variety of LaTeX
  174. % font selection schemes, but it could be as simple as "\def\UrlFont{\tt}".
  175. % In addition to setting "\UrlFont", some characters will probably need 
  176. % to be defined in the "\UrlSpecials" list because most fonts don't have 
  177. % all the standard input characters.  See the definition of "\url@rmstyle", 
  178. % which implements "\urlstyle{rm}".  Or even better, follow the definition
  179. % of "\url@sfstyle", which executes "\url@rmstyle" and then redefines
  180. % just "\UrlFont".  The nominal format for each special character "c" 
  181. % in the "\UrlSpecials" list is: "\do\c{<definition>}", but you can 
  182. % include other definitions too.
  183. % Changing linebreaks:
  184. % The list of characters that allow line-breaks is given by "\UrlBreaks" 
  185. % and "\UrlBigBreaks", which have the format "\do\c" for character "c". 
  186. % The differences are that `BigBreaks' have a lower penalty and have 
  187. % different breakpoints when in sequence (as in "http://"): `BigBreaks' 
  188. % are treated as mathrels while `Breaks' are mathbins (see The TeXbook, 
  189. % p.170). In particular, a series of `BigBreak' characters will break at 
  190. % the end and only at the end; a series of `Break' characters will break 
  191. % after the first and after every following *pair*; there will be no 
  192. % break after a `Break' character if a `BigBreak' follows.  In the case 
  193. % of "http://" it doesn't matter whether ":" is a `Break' or `BigBreak' --
  194. % the breaks are the same in either case; but for DECnet nodes with "::"
  195. % it is important to prevent breaks *between* the colons, and that is why 
  196. % colons are `BigBreaks'.
  197. % It is possible for characters to prevent breaks after the next following 
  198. % character (I use this for parentheses).  Specify these in "\UrlNoBreaks". 
  199. % You can do arbitrarily complex things with characters by making them 
  200. % active in math mode (mathcode hex-8000) and specifying the definition(s)
  201. % in "\UrlSpecials".  This is used in the rm and sf styles to handle 
  202. % several characters that are not present in fonts.
  203. % If all this sounds confusing ... well, it is!  But I hope you won't need 
  204. % to redefine breakpoints -- the default assignments seem to work well for 
  205. % a wide variety of applications.  If you do need to make changes, you can 
  206. % test for breakpoints using regular math mode and the characters "+=(a".
  207. % Yet more flexibility:
  208. % You can also set up url.sty to do multiple things with the verbatim text
  209. % by defining "\Url@use", but the format of the definition is special:
  210. %    \def\Url@use#1\,{ ... do things with #1 ... }
  211. % Yes, that is "#1" followed by "\," then the definition.  For example, 
  212. % to put a hypertext link in the DVI file:
  213. %    \def\Url@use#1\,{\special{html:<a href="#1">}#1\special{html:</a>}}
  214. % The End
  215. % ver 1.1 6-Feb-1996:  
  216. % Fix hyphens that wouldn't break and ligatures that weren't suppressed.
  217. Test file integrity:  ASCII 32-57, 58-126:  !"#$%&'()*+,-./0123456789
  218. :;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  219.